home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.2 Applications 1996 May / SGI IRIX 6.2 Applications 1996 May.iso / dist / impr_dev.idb / usr / impressario / src / examples / libpod / info.c.z / info.c
C/C++ Source or Header  |  1996-05-06  |  12KB  |  360 lines

  1. /**************************************************************************
  2.  *
  3.  *           Copyright (c)    1992 Silicon Graphics, Inc.
  4.  *            All Rights Reserved
  5.  *
  6.  *       THIS    IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
  7.  *
  8.  * The copyright notice above does not evidence any actual of intended
  9.  * publication of such source code, and is an unpublished work by Silicon
  10.  * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
  11.  * the property of Silicon Graphics, Inc. Any use, duplication or
  12.  * disclosure not specifically authorized by Silicon Graphics is strictly
  13.  * prohibited.
  14.  *
  15.  * RESTRICTED RIGHTS LEGEND:
  16.  *
  17.  * Use, duplication or disclosure by the Government is subject to
  18.  * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
  19.  * Technical Data and Computer Software clause at DFARS 52.227-7013,
  20.  * and/or in similar or successor clauses in the FAR, DOD or NASA FAR
  21.  * Supplement. Unpublished - rights reserved under the Copyright Laws of
  22.  * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
  23.  * Shoreline Blvd., Mountain View, CA 94039-7311
  24.  **************************************************************************
  25.  *
  26.  * File: info.c
  27.  *
  28.  * Description: Sample program that demonstrates the use of the standard
  29.  *    form of the libpod info read function.
  30.  *
  31.  *    Usage: info printer_name
  32.  *
  33.  **************************************************************************/
  34.  
  35.  
  36. #ident "$Revision: 1.4 $"
  37.  
  38.  
  39. #include <stdio.h>
  40. #include <string.h>
  41. #include <stdlib.h>
  42. #include <time.h>
  43. #include <pod.h>
  44.  
  45.  
  46. #define HANDLE_ERROR(pname)    { \
  47.                 PDPerror(pname); \
  48.                 exit(1); \
  49.                 }
  50.  
  51.  
  52. void usage(char*);
  53. void disp_info(PDInfoStruct*, time_t*);
  54. void disp_opstatus(int);
  55. void disp_status(PDStatusStruct*, PDMessageStruct*);
  56. void disp_config(PDInfoStruct*);
  57. void disp_colorspace(int);
  58. void disp_depth(int);
  59. void disp_format(int);
  60. void disp_pagesize(PDSizeTableStruct*);
  61.  
  62.  
  63. int main(int argc, char **argv)
  64. {
  65.     PDInfoStruct *info;
  66.     time_t mod_time;
  67.  
  68.     /*
  69.      * Get the printer name from command line
  70.      */
  71.     if (argc < 2) {
  72.     usage(argv[0]);
  73.     exit(1);
  74.     }
  75.  
  76.     /*
  77.      * Read and display info structure
  78.      */
  79.     if (PDReadInfo(argv[1], &info, &mod_time) < 0)
  80.     HANDLE_ERROR(argv[0]);
  81.     disp_info(info, &mod_time);
  82.  
  83.     return 0;
  84. }
  85.  
  86.  
  87. void usage(char *progname)
  88. {
  89.     (void)fprintf(stderr, "Usage: %s printer_name\n", progname);
  90. }
  91.  
  92.  
  93. void disp_info(PDInfoStruct *info, time_t *mod_timep)
  94. {
  95.     (void)printf("Last Information Modification: %s\n", ctime(mod_timep));
  96.     (void)printf("Status Information\n");
  97.     disp_status(info->active_status, info->error_status);
  98.     (void)printf("\nConfiguration Information\n");
  99.     disp_config(info);
  100. }
  101.  
  102.  
  103. void disp_status(PDStatusStruct *status, PDMessageStruct *messages)
  104. {
  105.     register int i;
  106.     char *options;
  107.  
  108.     disp_opstatus(status->operational_status);
  109.     (void)printf("\tMedia type code:            %d\n", status->media_type);
  110.     (void)printf("\tNumber of colors code:      0x%08X\n",
  111.                                                 status->number_of_colors);
  112.     (void)printf("\t\tNumber of colors:   %d\n",
  113.                                 PD_GET_NUMCOLORS(status->number_of_colors));
  114.     disp_colorspace(PD_GET_COLORSPACE_CODE(status->number_of_colors));
  115.     disp_depth(PD_GET_DEPTH_CODE(status->number_of_colors));
  116.     disp_format(PD_GET_FORMAT_CODE(status->number_of_colors));
  117.     (void)printf("\tMedia size code:            0x%08X\n", status->media_size);
  118.     (void)printf("\tMedia size name:            %s\n",
  119.                             PDGetNameBySizeCode(status->media_size));
  120.     options = status->printer_options;
  121.     (void)printf("\tInstalled options:          %s\n",
  122.             (options && *options != '\0') ? options: "None");
  123.     (void)printf("\tMedia size validation mask: %d\n", status->validation_mask);
  124.     (void)printf("\tNumber of messages:         %d\n", status->error_count);
  125.     for (i = 0; i < status->error_count; i++) {
  126.     (void)printf("\n\t\tMessage %d code: 0x%08X\n", i+1,
  127.                     messages[i].message_code);
  128.     (void)printf("\t\tMessage %d text: %s\n", i+1,
  129.                     messages[i].message_text);
  130.     }
  131. }
  132.  
  133.  
  134. void disp_opstatus(int status)
  135. {
  136.     (void)printf("\tOperational status:         ");
  137.     switch(status) {
  138.     case PD_STATUS_IDLE:
  139.         (void)printf("IDLE");
  140.         break;
  141.     case PD_STATUS_BUSY:
  142.         (void)printf("BUSY");
  143.         break;
  144.     case PD_STATUS_FAULTED:
  145.         (void)printf("FAULTED");
  146.         break;
  147.     case PD_STATUS_UNAVAILABLE:
  148.         (void)printf("UNAVAILABLE");
  149.         break;
  150.     default:
  151.         (void)printf("UNKNOWN");
  152.         break;
  153.     }
  154.     (void)printf("\n");
  155. }
  156.  
  157.  
  158. void disp_config(PDInfoStruct *info)
  159. {
  160.     register int i;
  161.  
  162.     (void)printf("\tPrinter class: %s\n", info->printer_class);
  163.     (void)printf("\tPrinter model: %s\n", info->printer_model);
  164.     (void)printf("\tPrinter options: %s\n", info->printer_options);
  165.     (void)printf("\tLocation code: %s\n", info->location_code);
  166.     (void)printf("\tPhysical location: %s\n", info->physical_location);
  167.     (void)printf("\tTechnology: %s\n", info->technology);
  168.     (void)printf("\n");
  169.  
  170.     (void)printf("\tConfig file pathname: %s\n", info->config_path);
  171.     (void)printf("\tDriver pathname: %s\n", info->driver_path);
  172.     (void)printf("\tPort pathname: %s\n", info->port_path);
  173.     (void)printf("\tStatus file pathname: %s\n", info->active_path);
  174.     (void)printf("\n");
  175.  
  176.     (void)printf("\tError retry wait: %d\n", info->error_retry_wait);
  177.     (void)printf("\tStatus update wait: %d\n", info->status_update_wait);
  178.     (void)printf("\tMedia wait: %d\n", info->media_wait);
  179.     (void)printf("\n");
  180.  
  181.     (void)printf("\tHorizontal resolution: %d\n", info->horizontal_resolution);
  182.     (void)printf("\tVertical resolution: %d\n", info->vertical_resolution);
  183.     (void)printf("\n");
  184.  
  185.     (void)printf("\tCost per page: %f\n", info->cost_per_page);
  186.     (void)printf("\tAve. time per page: %d\n", info->avg_time_per_page);
  187.     (void)printf("\tMax. time per page: %d\n", info->max_time_per_page);
  188.     (void)printf("\n");
  189.  
  190.     (void)printf("\tMin. number of colors: %d\n", info->min_number_of_colors);
  191.     (void)printf("\tMax. number of colors: %d\n", info->max_number_of_colors);
  192.     (void)printf("\n");
  193.  
  194.     (void)printf("\tMin. horizontal area (in.): %f\n",
  195.                         info->min_area_horizontal);
  196.     (void)printf("\tMin. vertical area (in.): %f\n", info->min_area_vertical);
  197.     (void)printf("\tMax. horizontal area (in.): %f\n",
  198.                         info->max_area_horizontal);
  199.     (void)printf("\tMax. vertical area (in.): %f\n", info->max_area_vertical);
  200.     (void)printf("\n");
  201.  
  202.     (void)printf("\tMin. horizontal area (dots): %d\n",
  203.                         info->min_addr_horizontal);
  204.     (void)printf("\tMin. vertical area (dots): %d\n", info->min_addr_vertical);
  205.     (void)printf("\tMax. horizontal area (dots): %d\n",
  206.                         info->max_addr_horizontal);
  207.     (void)printf("\tMax. vertical area (dots): %d\n", info->max_addr_vertical);
  208.     (void)printf("\n");
  209.  
  210.     (void)printf("\tNumber of quality modes: %d\n", info->quality_modes);
  211.     for (i = 0; i < info->quality_modes; i++)
  212.         (void)printf("\t\tQuality mode %d: %s\n", i+1,
  213.                         info->quality_mode_names[i]);
  214.     if (info->quality_modes)
  215.         (void)printf("\tDefault quality mode: %s\n",
  216.             info->quality_mode_names[info->default_quality_mode-1]);
  217.     (void)printf("\n");
  218.  
  219.     (void)printf("\tManual capable: %s\n", (info->manual_capable) ?
  220.                                 "Yes": "No");
  221.     (void)printf("\tBlack substitute: %s\n", (info->black_substitute) ?
  222.                                 "Yes": "No");
  223.     (void)printf("\tMedia standard: %d\n", info->media_standard);
  224.     (void)printf("\n");
  225.  
  226.     (void)printf("\tNumber of fonts: %d\n", info->avail_fonts);
  227.     for (i = 0; i < info->avail_fonts; i++)
  228.         (void)printf("\t\tFont name %d: %s\n", i+1, info->avail_fonts_names[i]);
  229.     (void)printf("\n");
  230.  
  231.     (void)printf("\tNumber of input sources: %d\n", info->input_sources);
  232.     for (i = 0; i < info->input_sources; i++)
  233.         (void)printf("\t\tInput source %d: %s\n", i+1,
  234.                         info->input_sources_names[i]);
  235.     if (info->input_sources)
  236.         (void)printf("\tDefault input source: %s\n",
  237.             info->input_sources_names[info->default_input_source-1]);
  238.     (void)printf("\tInput source gamma: %f\n", info->input_source_gamma);
  239.     (void)printf("\n");
  240.  
  241.     (void)printf("\tNumber of color adj. schemes: %d\n",
  242.                         info->color_adjustment);
  243.     for (i = 0; i < info->color_adjustment; i++)
  244.         (void)printf("\t\tAdj. scheme %d: %s\n", i+1, info->color_adj_names[i]);
  245.     if (info->color_adjustment)
  246.         (void)printf("\tDefault adj. scheme: %s\n",
  247.             info->color_adj_names[info->default_color_adj-1]);
  248.     (void)printf("\n");
  249.  
  250.     (void)printf("\tNumber of media types: %d\n", info->media_types);
  251.     for (i = 0; i < info->media_types; i++)
  252.         (void)printf("\t\tMedia type %d: %s\n", i+1,
  253.                         info->media_types_names[i]);
  254.     if (info->media_types)
  255.         (void)printf("\tDefault media type: %s\n",
  256.             info->media_types_names[info->default_media_type-1]);
  257.     (void)printf("\n");
  258.  
  259.     (void)printf("\tNumber of size table entries: %d\n",
  260.                         info->size_table_entries);
  261.     for (i = 0; i < info->size_table_entries; i++) {
  262.         (void)printf("\t\tEntry %d:\n", i+1);
  263.     disp_pagesize(&info->size_table[i]);
  264.     }
  265.     (void)printf("\n");
  266. }
  267.  
  268.  
  269. void disp_colorspace(int cspace)
  270. {
  271.     (void)printf("\t\tColorspace:         ");
  272.     switch(cspace) {
  273.         case PD_DATA_K:
  274.             (void)printf("k\n");
  275.             break;
  276.         case PD_DATA_CMY:
  277.             (void)printf("cmy\n");
  278.             break;
  279.         case PD_DATA_CMYK:
  280.             (void)printf("cmyk\n");
  281.             break;
  282.         case PD_DATA_W:
  283.             (void)printf("w\n");
  284.             break;
  285.         case PD_DATA_RGB:
  286.             (void)printf("rgb\n");
  287.             break;
  288.         case PD_DATA_YMC:
  289.             (void)printf("ymc\n");
  290.             break;
  291.         case PD_DATA_YMCK:
  292.             (void)printf("ymck\n");
  293.             break;
  294.         case PD_DATA_KCMY:
  295.             (void)printf("kcmy\n");
  296.             break;
  297.         default:
  298.             (void)printf("0x%08X\n", cspace);
  299.             break;
  300.     }
  301. }
  302.  
  303.  
  304. void disp_depth(int depth)
  305. {
  306.     (void)printf("\t\tDepth:              ");
  307.     switch(depth) {
  308.         case PD_DATA_DEPTH1:
  309.             (void)printf("1 bpp\n");
  310.             break;
  311.         case PD_DATA_DEPTH4:
  312.             (void)printf("4 bpp\n");
  313.             break;
  314.         case PD_DATA_DEPTH8:
  315.             (void)printf("8 bpp\n");
  316.             break;
  317.         default:
  318.             (void)printf("0x%08X\n", depth);
  319.             break;
  320.     }
  321. }
  322.  
  323.  
  324. void disp_format(int format)
  325. {
  326.     (void)printf("\t\tFormat:             ");
  327.     switch(format) {
  328.         case PD_DATA_CHUNKY:
  329.             (void)printf("chunky\n");
  330.             break;
  331.         case PD_DATA_BANDED:
  332.             (void)printf("banded\n");
  333.             break;
  334.         case PD_DATA_PLANAR:
  335.             (void)printf("planar\n");
  336.             break;
  337.         default:
  338.             (void)printf("0x%08X\n", format);
  339.             break;
  340.     }
  341. }
  342.  
  343.  
  344. void disp_pagesize(PDSizeTableStruct *size_info)
  345. {
  346.     (void)printf("\t\t\tMedia size: 0x%08X  %s\n", size_info->media_size,
  347.                         PDGetNameBySizeCode(size_info->media_size));
  348.     (void)printf( "\t\t\tOverall dimensions (inches): %.3f (h) by %.3f (v)\n",
  349.                 size_info->width, size_info->length);
  350.     (void)printf("\t\t\tMargins (inches): %.3f (l), %.3f (t)\n",
  351.                 size_info->left_margin, size_info->top_margin);
  352.     (void)printf("\t\t\tImageable dimensions (dots): %d (h) by %d (v)\n",
  353.                 size_info->horizontal_addr, size_info->vertical_addr);
  354.     (void)printf("\t\t\tRaster definition code: 0x%02X\n",
  355.                         size_info->raster_definition);
  356.     (void)printf("\t\t\tValidation mask: 0x%02X\n", size_info->validation_mask);
  357.     (void)printf("\t\t\tVariable page size code: 0x%02X\n",
  358.                         size_info->variable_page_size);
  359. }
  360.